import gettext

from util.yaml_util import load_yaml_config

# 设置语言环境
locale_path = 'locales'

default_language = load_yaml_config('config/application.yaml', 'app', 'language')


def load_messages(language) -> dict:
    # 加载翻译
    lang = gettext.translation('messages', localedir=locale_path, languages=[language], fallback=True)
    lang.install()
    _ = lang.gettext

    # 返回更新后的 MESSAGES
    return {
        'REQUEST_SUCCESS': _('Request successful'),
        'REQUEST_FAIL': _('Request failure'),
        'LOGIN_SUCCESS': _('Login successful'),
        'TOKEN_EXPIRED': _('Token has expired'),
        'INVALID_TOKEN': _('Invalid token'),
        'NO_AVAILABLE_ROLE': _('The user has no available role'),
        'INCORRECT_PASSWORD': _('The password is incorrect'),
        'USER_NOT_EXIST': _('User does not exist'),
        'REFRESH_TOKEN_EXPIRED': _('Refresh token has expired'),
        'INVALID_REFRESH_TOKEN': _('Invalid refresh token'),
        'INCORRECT_VERIFICATION_CODE': _('The verification code is incorrect'),
        'INVALID_AUTHORIZATION_HEADER': _('Invalid Authorization header'),
    }


messages = load_messages(default_language)
